/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.worsik.android.test.rideshare.util.listener;

import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import cz.worsik.android.test.rideshare.constants.ViewConst;

public class AllPickOnClickListener implements CompoundButton.OnCheckedChangeListener
{
	View layout;

	public AllPickOnClickListener(View layout) {
		this.layout = layout;
	}
		
	public void onCheckedChanged(CompoundButton btn, boolean checked) {
		if (ViewConst.DEBUG) {
			Log.i("ALL PICK EVENT","Nastavuji all na "+checked);
		}

		if (ViewConst.DEBUG) {
			Log.i("ALL PICK EVENT","Počet checkboxů: "+(ViewConst.CHECKBOX_COUNT));
		}
		switch(btn.getId())
		{
			case ViewConst.CHECKBOX_START_ID:

				for (int i=1; i<ViewConst.CHECKBOX_COUNT; i++)
				{
					int cb_id = ViewConst.CHECKBOX_START_ID+i;
					CheckBox checkbox = (CheckBox) layout.findViewById(cb_id);
					if (ViewConst.DEBUG) {
						Log.i("ALL PICK EVENT","Checkbox "+checkbox.getText()+" je "+checkbox.isChecked());
					}
					// pokud zaskrtavame, zaskrtneme nezaskrtnute, pokud rusime, zrusime zaskrtnute
					if ((checked && !checkbox.isChecked()) || (!checked && checkbox.isChecked()))
					{
						if (ViewConst.DEBUG) {
							Log.i("ALL PICK EVENT","Nastavuji "+checkbox.getText()+" na "+checked);
						}
						checkbox.setChecked(checked);
					}
				}

				break;
		}
	}	
}